package ryulib.graphic;

import android.app.Activity;
import android.util.DisplayMetrics;

public class ScreenResolution {
	
	public ScreenResolution(Activity activity) {
		DisplayMetrics displayMetrics = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
		
		if (displayMetrics.widthPixels > displayMetrics.heightPixels) {
			_Width  = displayMetrics.widthPixels;
			_Height = displayMetrics.heightPixels;
		} else {
			_Width  = displayMetrics.heightPixels;
			_Height = displayMetrics.widthPixels;
		}
	}
	
	private int _Width = 0;
	private int _Height = 0;
	
	
	public int getWidth() {
		return _Width;
	}
	
	public int getHeight() {
		return _Height;
	}
	
	public double getScreenRatio(int width, int height) {
		if (width < height) {
			int temp = width;
			width = height;
			height = temp;
		}		
		
		double ratio = 1.0;
		
		double ratioW = ((double) _Width ) / ((double) width); 
		double ratioH = ((double) _Height) / ((double) height);
		
		if (ratioW > ratioH) ratio = ratioH;
		else ratio = ratioW;
		
		return ratio;
	}

}
